- name: check/create instance
  hosts: 209.132.184.143
  user: root
  gather_facts: False

  vars_files: 
   - /srv/web/infra/ansible/vars/global.yml
   - "{{ private }}/vars.yml"

  tasks:
  - include: "{{ tasks }}/persistent_cloud.yml"
  - include: "{{ tasks }}/growroot_cloud.yml"

- name: provision instance
  hosts: 209.132.184.143
  user: root
  gather_facts: True

  vars_files: 
   - /srv/web/infra/ansible/vars/global.yml
   - "{{ private }}/vars.yml"
   - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml

  tasks:
  - include: "{{ tasks }}/cloud_setup_basic.yml"
  - include: "{{ tasks }}/postfix_basic.yml"

  - name: mount up disk of persistent storage
    action: mount name=/srv/persist src='LABEL=artboard' fstype=ext4 state=mounted

  # open up ports (22, 80, 443)
  - name: poke holes in the firewall
    action: command lokkit {{ item }}
    with_items:
    - --service=ssh
    - --service=https
    - --service=http

  # packages needed
  - name: add packages
    action: yum state=present name={{ item }}
    with_items:
    - rsync
    - openssh-clients
    - httpd
    - httpd-tools
    - php
    - php-gd
    - php-mysql
    - cronie-noanacron

  # packages needed to be gone
  - name: erase packages
    action: yum state=absent name={{ item }}
    with_items:
    - cronie-anacron

  - name: artboard backup thing
    action: copy src="{{ files }}/artboard/artboard-backup" dest=/etc/cron.daily/artboard-backup mode=0755

  - name: make artboard subdir 
    action: file path=/srv/persist/artboard mode=0755 state=directory

  - name: link artboard into /var/www/html
    action: file state=link src=/srv/persist/artboard path=/var/www/html/artboard

  - name: add apache confs
    action: copy src="{{ files }}/artboard/{{ item }}" dest="/etc/httpd/conf.d/{{ item }}"  backup=true
    with_items:
    - artboard.conf
    - redirect.conf
    notify: restart httpd
    
  - name: startup apache
    action: service name=httpd state=started

  handlers:
  - include: "{{ handlers }}/restart_services.yml"
